package com.myWeb.controller;

import com.myWeb.dao.QuestionDao;
import com.myWeb.entity.Question;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "QuestionAddServlet")
public class QuestionAddServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String title,questionA,questionB,questionC,questionD,answer;
        int result = 0;

        title = request.getParameter("title");
        questionA = request.getParameter("questionA");
        questionB = request.getParameter("questionB");
        questionC = request.getParameter("questionC");
        questionD = request.getParameter("questionD");
        answer = request.getParameter("answer");

        QuestionDao dao = new QuestionDao();
        Question question = new Question(null,title,questionA,questionB,questionC,questionD,answer);

        result = dao.add(question,request);

        if(result == 1){
            request.setAttribute("info","试题添加成功");
        }else{
            request.setAttribute("info","试题添加失败");
        }

        request.getRequestDispatcher("/info.jsp").forward(request,response);
    }
}
